﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TomatoClock.Models;
using TomatoClock.Services;

namespace TomatoClock.ViewModels
{
    public class MainViewModel
    {
        public User CurrentUser { get; set; }
        public List<PomodoroTask> Tasks => CurrentUser.Tasks;
        public List<Achievement> Achievements => CurrentUser.data.Achievements;

        public DataService dataService;

        public MainViewModel(DataService dataService)
        {
            this.dataService = dataService;
            CurrentUser = new User();
        }
        public MainViewModel(DataService dataService, User currentUser)
        {
            this.dataService=dataService;
            this.CurrentUser = currentUser;
        }

        public void SetPomodoroTimer(string name, int duration)
        {
            // 设置番茄钟逻辑，例如创建一个新任务并添加到用户的任务列表中
            var task = new PomodoroTask
            {
                Name = name,
                Duration = duration,
                Type = "Work",
                StartTime = DateTime.Now
            };
            AddTask(task);
        }

        public void StartTask(PomodoroTask task)
        {
            // Start task logic
        }

        public void StopTask(PomodoroTask task)
        {
            // Stop task logic
        }

        public void CompleteTask(PomodoroTask task)
        {
            task.IsCompleted = true;
            dataService.AddPomodoroTask(task);
            // Additional logic for completing task
        }

        public void AddTask(PomodoroTask task) => Tasks.Add(task);

        public void AddAchievement(Achievement achievement) => Achievements.Add(achievement);

        // Other business logic
    }
}
